// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   check_delete_ok.java

package manufacture.design_module;

import include.nseer_cookie.counter;
import include.nseer_cookie.exchange;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import validata.ValidataNumber;
import validata.ValidataTag;

public class check_delete_ok extends HttpServlet
{

	public check_delete_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		nseer_db_backup1 manufacture_db = new nseer_db_backup1(dbApplication);
		nseer_db_backup1 manufacture_db1 = new nseer_db_backup1(dbApplication);
		ValidataNumber validata = new ValidataNumber();
		ValidataTag vt = new ValidataTag();
		counter count = new counter(dbApplication);
		try
		{
			if (manufacture_db.conn((String)dbSession.getAttribute("unit_db_name")) && manufacture_db1.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String config_id = request.getParameter("config_id");
				String design_ID = request.getParameter("design_ID");
				String product_ID = request.getParameter("product_ID");
				String bodyc = new String(request.getParameter("check_suggestion").getBytes("UTF-8"), "UTF-8");
				String choice = request.getParameter("choice");
				String check_suggestion = exchange.toHtml(bodyc);
				String check_time = request.getParameter("check_time");
				String checker = request.getParameter("checker");
				String sql6 = (new StringBuilder("select id from manufacture_workflow where object_ID='")).append(design_ID).append("' and type_id='02' and ((check_tag='0' and config_id<'").append(config_id).append("') or (check_tag='1' and config_id='").append(config_id).append("'))").toString();
				ResultSet rs6 = manufacture_db.executeQuery(sql6);
				if (!rs6.next())
				{
					if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "manufacture_design_procedure", "design_ID", design_ID, "design_module_tag").equals("1"))
					{
						if (choice != null)
						{
							if (choice.equals(""))
							{
								String sql = (new StringBuilder("delete from manufacture_workflow where object_ID='")).append(design_ID).append("'").toString();
								manufacture_db.executeUpdate(sql);
								sql = (new StringBuilder("update manufacture_design_procedure set check_time='")).append(check_time).append("',checker='").append(checker).append("',check_suggestion='").append(check_suggestion).append("',design_module_tag='9' where design_ID='").append(design_ID).append("'").toString();
								manufacture_db.executeUpdate(sql);
								String sql4 = (new StringBuilder("select * from manufacture_design_procedure where design_ID='")).append(design_ID).append("'").toString();
								ResultSet rs4 = manufacture_db.executeQuery(sql4);
								if (rs4.next())
								{
									String sql5 = (new StringBuilder("update manufacture_design_procedure_details set design_module_change_tag='1',module_subtotal='0',design_module_tag='0' where design_ID='")).append(rs4.getString("design_ID")).append("'").toString();
									sql6 = (new StringBuilder("delete from manufacture_design_procedure_module_details where design_ID='")).append(rs4.getString("design_ID")).append("'").toString();
									manufacture_db.executeUpdate(sql5);
									manufacture_db.executeUpdate(sql6);
								}
								String design_ID1 = "";
								String sql1 = (new StringBuilder("select * from design_module where product_ID='")).append(product_ID).append("' and check_tag='1'").toString();
								ResultSet rs1 = manufacture_db1.executeQuery(sql1);
								if (rs1.next())
									design_ID1 = rs1.getString("design_ID");
								String sql2 = (new StringBuilder("select * from design_module_details where design_ID='")).append(design_ID1).append("'").toString();
								String sql3;
								for (ResultSet rs2 = manufacture_db1.executeQuery(sql2); rs2.next(); manufacture_db.executeUpdate(sql3))
									sql3 = (new StringBuilder("update design_module_details set design_balance_amount='")).append(rs2.getString("amount")).append("' where id='").append(rs2.getString("id")).append("'").toString();

							} else
							{
								sql6 = (new StringBuilder("select id from manufacture_workflow where object_ID='")).append(design_ID).append("' and config_id<'").append(config_id).append("' and config_id>='").append(choice).append("'").toString();
								String sql;
								for (rs6 = manufacture_db.executeQuery(sql6); rs6.next(); manufacture_db1.executeUpdate(sql))
									sql = (new StringBuilder("update manufacture_workflow set check_tag='0' where id='")).append(rs6.getString("id")).append("'").toString();

							}
							response.sendRedirect("manufacture/design_module/check_delete_ok.jsp?finished_tag=0");
						} else
						{
							response.sendRedirect("manufacture/design_module/check_delete_ok.jsp?finished_tag=1");
						}
					} else
					{
						response.sendRedirect("manufacture/design_module/check_delete_ok.jsp?finished_tag=3");
					}
				} else
				{
					response.sendRedirect("manufacture/design_module/check_delete_ok.jsp?finished_tag=2");
				}
				manufacture_db.commit();
				manufacture_db1.commit();
				manufacture_db.close();
				manufacture_db1.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
